package beusoft.ccjk.com.apt.util;

import javax.annotation.processing.ProcessingEnvironment;
import javax.lang.model.element.Element;
import javax.lang.model.element.ExecutableElement;
import javax.lang.model.element.TypeElement;
import javax.lang.model.element.VariableElement;

/**
 * Created by CCJK on 2018/11/24.
 */

public class AnnotationUtil {
    /**
     * @param processingEnv
     * @param element
     * @return
     */
    public static String getPackageName(ProcessingEnvironment processingEnv, Element element) {
        return processingEnv.getElementUtils().getPackageOf(element).getQualifiedName().toString();
    }

    public static String getClassFullName(Element element) {
        if (element instanceof ExecutableElement) {
            return ((TypeElement) element.getEnclosingElement()).getQualifiedName().toString();
        } else if (element instanceof VariableElement) {
            return ((TypeElement) (element.getEnclosingElement().getEnclosingElement())).getQualifiedName().toString();
        }
        else if (element instanceof TypeElement) {
            return ((TypeElement) element).getQualifiedName().toString();
        }


        return null;
    }
}
